home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / libraries / dylan / ext.dylan < prev    next >
Encoding:
Text File  |  1995-03-15  |  3.7 KB  |  111 lines  |  [TEXT/ttxt]

  1. module: extensions
  2. rcs-header: $Header: ext.dylan,v 1.6 94/11/22 16:56:19 nkramer Exp $
  3.  
  4. //======================================================================
  5. //
  6. // Copyright (c) 1994  Carnegie Mellon University
  7. // All rights reserved.
  8. // 
  9. // Use and copying of this software and preparation of derivative
  10. // works based on this software are permitted, including commercial
  11. // use, provided that the following conditions are observed:
  12. // 
  13. // 1. This copyright notice must be retained in full on any copies
  14. //    and on appropriate parts of any derivative works.
  15. // 2. Documentation (paper or online) accompanying any system that
  16. //    incorporates this software, or any part of it, must acknowledge
  17. //    the contribution of the Gwydion Project at Carnegie Mellon
  18. //    University.
  19. // 
  20. // This software is made available "as is".  Neither the authors nor
  21. // Carnegie Mellon University make any warranty about the software,
  22. // its performance, or its conformity to any specification.
  23. // 
  24. // Bug reports, questions, comments, and suggestions should be sent by
  25. // E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  26. //
  27. //======================================================================
  28. //
  29. //  This file contains some random things that don't really fit anywhere
  30. //  else.
  31. //
  32.  
  33. /// One-of -- Exported.
  34. ///
  35. /// One-of takes any number of objects as arguments.  It returns a type that
  36. /// represents the argument values as an enumeration (singleton values in
  37. /// Dylan).
  38. ///
  39. define constant one-of =
  40.   method (thing, #rest more-things) => result :: <type>;
  41.     reduce(union, singleton(thing), map(singleton, more-things));
  42.   end;
  43.  
  44. /// Type-or -- Exported.
  45. ///
  46. /// Type-or takes any number of types as arguments and returns a type that is
  47. /// the union of all the argument types.
  48. ///
  49. define constant type-or =
  50.   method (type :: <type>, #rest more-types) => result :: <type>;
  51.   // Make sure all of more-types are <type>s.
  52.     do(rcurry(check-type, <type>), more-types);
  53.   // Make a union out of them.
  54.     reduce(union, type, more-types);
  55.   end;
  56.  
  57. /// false-or -- Exported.
  58. ///
  59. /// False-or takes a type and returns a type that is the union of the argument
  60. /// type and the type singleton(#f).
  61. ///
  62. define constant false-or
  63.     = method (type :: <type>) => new-type :: <type>;
  64.     union(type, singleton(#f));
  65.       end;
  66.  
  67. /// Ignore -- Exported.
  68. ///
  69. /// Ignore takes any number of arguments and ignores them.  This is useful
  70. /// when extending functions that require arguments for which the new method
  71. /// has no use.  This function provides documentation to the code reader,
  72. /// and it provides a reference to the unneeded local variables so that
  73. /// compilers do not flame about unused locals.
  74. ///
  75. define constant ignore =
  76.   method (#rest noise)
  77.     noise;
  78.     #f;
  79.   end;
  80.  
  81. // Key-exists -- Exported
  82. //
  83. // If the given key is present in the collection, return #t and the value
  84. // associated with the key.  Otherwise, return #f and an undefined value.
  85. //
  86. define constant undefined = pair(#f, #f);
  87. define constant key-exists? =
  88.   method (coll :: <collection>, key :: <object>)
  89.    => (result :: <boolean>, value :: <object>);
  90.     let value = element(coll, key, default: undefined);
  91.     values(value ~= undefined, value);
  92.   end method;
  93.  
  94. // <dictionary> -- Exported
  95. //
  96. // What <table> and <self-organizing-list> are subclasses of.  (If you
  97. // want the semantics of a <table> but don't necessarily want a hash
  98. // table implementation, this is what you should use)
  99. //
  100. define abstract class <dictionary> (<mutable-explicit-key-collection>,
  101.                     <stretchy-collection>)
  102. end class <dictionary>;
  103.  
  104.  
  105.  
  106. // remove-key! -- Created by the Dylan module
  107. //
  108. define open generic remove-key! (dictionary :: <dictionary>, key :: <object>) 
  109.  => new_dictionary :: <dictionary>;
  110.  
  111.